package com.dragon.english_practice_back.controller;

import com.dragon.english_practice_back.service.AuthenticationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/")
public class HelloController {
    @Autowired
    AuthenticationUtil authenticationUtil;
    @GetMapping("hello")
    public Object hello(){
        return "hello world!";

    }
    @GetMapping("helloUser")
    @PreAuthorize("hasAnyRole('USER')")
    public Object helloUser(){
        return "hello user "+ authenticationUtil.getUser().getEmail()+"!";
    }
    @GetMapping("helloAdmin")
    @PreAuthorize("hasAnyRole('ADMIN')")
    public Object helloAdmin(){
        return "hello admin "+ authenticationUtil.getUser().getEmail()+"!";
    }
}
